package com.wtgroup.demo.draft;

import com.wtgroup.demo.common.judge.Judger;
import com.wtgroup.demo.common.util.RandomUtil;
import com.wtgroup.demo.common.util.Sout;
import com.wtgroup.demo.common.util.Tools;

import java.util.Arrays;

public class D {
    public static void main(String[] args) {

        Judger.of(() -> {
                    int[] arr = RandomUtil.randomArray(1000, -100, 100);
                    selectSort(arr);
                    int[] arr2 = Arrays.copyOf(arr, arr.length);
                    insertSort(arr2);
                    boolean r = Tools.equals(arr, arr2);
                    return r;
                })
                .setIterCount(10)
                .start()
                .print();

    }

    static void selectSort(int[] arr) {
        int N = arr.length;
        if (N < 2) {
            return;
        }
        for (int i = 0; i < arr.length; i++) {
            int curr = arr[i];
            int minIx = i;
            int min = arr[i];
            int j = i + 1;
            for (; j < arr.length; j++) {
                if (arr[j] < min) {
                    min = arr[j];
                    minIx = j;
                }
            }

            int tmp = arr[i];
            arr[i] = arr[minIx];
            arr[minIx] = tmp;

        }

    }

    static void insertSort(int[] arr) {
        int N = arr.length;
        for (int i = 1; i < N; i++) {
            int curr = arr[i];
            int j = i - 1;
            while (j >= 0 && curr < arr[j]) {
                arr[j + 1] = arr[j]; // 后移
                j--;
            }
            // 插入
            arr[j + 1] = curr;
        }
    }

    static void bubbleSort(int[] arr) {

    }
}
